/**
 * 
 */
package com.alstudio.module.xmpp.EventHandler.xmpp;

import java.util.ArrayList;
import java.util.HashMap;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.core.voip.CallDetail;
import com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener;
import com.alstudio.module.xmpp.protocol.xmpp.data.ALXmppConnectionState;
import com.alstudio.module.xmpp.protocol.xmpp.data.ALXmppEventType;
import com.alstudio.module.xmpp.protocol.xmpp.data.VauthData;
import com.alstudio.module.xmpp.protocol.xmpp.data.economic.EconomicRecords;
import com.alstudio.module.xmpp.protocol.xmpp.data.economic.RechargeItem;
import com.alstudio.module.xmpp.protocol.xmpp.packact.ALMessage;
import com.alstudio.pojo.ALXmppEvent;
import com.alstudio.pojo.module.dating.DatingUser;
import com.alstudio.pojo.module.local.CallPrice;
import com.alstudio.pojo.module.local.Prop;
import com.alstudio.pojo.module.local.Props;
import com.alstudio.pojo.module.local.PropsDetail;
import com.alstudio.pojo.module.user.User;
import com.alstudio.utils.log.ALLog;
import com.alstudio.utils.notification.SystemSettings;

/**
 * 此类用于监听网络层传递上来的xmpp事件，经过封装后，将事件通知到ui层
 * 
 * @author alonso lee
 * 
 */
public class ALXmppEventHandler implements ALXmppEventListener {

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.net.callback.ALXmppEventListener#onConnectLostEvent(java
	 * .lang .String)
	 */
	@Override
	public void onConnectLostEvent(String reason) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CONNECTION_LOST_EVENT);
		data.setErrorMessage(reason);

		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.net.callback.ALXmppEventListener#onLoginedEvent(java.lang.
	 * String, java.lang.String)
	 */
	@Override
	public void onLoginedEvent(String jid, String pwd, String token) {
		// TODO Auto-generated method stub
		// 回调到主线程
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CONNECTION_ESTABLISHED_EVENT);
		data.setJid(jid);
		data.setPwd(pwd);
		data.setToken(token);

		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
		// ALLocalEnv.adapter.xmppSendPresence();
		// ALLocalEnv.adapter.xmppSendPingRequest();

		// ALLocalEnv.adapter.xmppSendFeedBack();
		ALLog.d("发送出席");
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.net.callback.ALXmppEventListener#onLogoutEvent()
	 */
	@Override
	public void onLogoutEvent() {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_LOGOUT_SUCCESS_EVENT);

		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onAuthFailedEvent(String msg) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_AUTH_FAILED_EVENT);
		data.setErrorMessage(msg);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.net.callback.ALXmppEventListener#onConnectStateChangedEvent
	 * (int, int)
	 */
	@Override
	public void onConnectStateChangedEvent(ALXmppConnectionState newState,
			ALXmppConnectionState oldState) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CONNECTION_STATE_CHANGED_EVENT);
		data.setNewConnectionState(newState);
		data.setLastConnectionState(oldState);

		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onSessionIdUpdateEvent(java.lang.String)
	 */
	@Override
	public void onSessionIdUpdateEvent(String sid) {
		// TODO Auto-generated method stub

		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_UPDATE_XMPP_SESSION_ID_EVENT);
		data.setCurXmppSessionId(sid);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onRegisterEvent
	 * (java.lang.String, java.lang.String, java.lang.String, int)
	 */
	@Override
	public void onRegisterEvent(String jid, String password, String user,
			int code) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(ALXmppEventType.XMPP_REGISTER_EVENT);
		data.setJid(jid);
		data.setPwd(password);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onThirdPartLoginResult(java.lang.String, java.lang.String)
	 */
	@Override
	public void onThirdPartLoginResult(String uid, String password) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHECK_THIRD_PART_REGISTER_EVENT);
		data.setJid(uid);
		data.setPwd(password);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onCheckEmailResult
	 * (boolean)
	 */
	@Override
	public void onCheckEmailResult(boolean isRegistered) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHECK_EMAIL_EVENT);
		data.setBoolean(isRegistered);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.net.callback.ALXmppEventListener#onUnkonwErrorEvent(java
	 * .lang .String)
	 */
	@Override
	public void onUnkonwErrorEvent(String errorMessage) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onConnectLostEvent(String reason, String conflictSid) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CONNECTION_LOST_EVENT);
		data.setErrorMessage(reason);
		data.setConflictId(conflictSid);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onChangePasswordEvent(int, java.lang.String)
	 */
	@Override
	public void onChangePasswordEvent(int code, String newPwd) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHANGE_PASSWORD_RESULT);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/***************************************** message 消息处理 ***************************************************/
	@Override
	public void onReceiveMessage(ALMessage msg) {
		// TODO Auto-generated method stub
		handleNewMessage(msg);
	}

	@Override
	public void onReceiveMessageBackEvent(String from, String id) {
		// TODO Auto-generated method stub
		ALLog.d("收到来自 " + from + " 的消息回执。id为  " + id);
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_MESSAGE_BACK_RECEIVE_EVENT);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onPresenceStatusEvent(String user, String show) {
		// TODO Auto-generated method stub
		ALLog.d("收到Presence状态变换 " + user + "  " + show);
	}

	@Override
	public void onGetPingPackageEvent(boolean c2s) {
		// TODO Auto-generated method stub
		if (c2s) {
			ALLog.d("服务器响应c2s心跳包");
			ALXmppEvent data = new ALXmppEvent(
					ALXmppEventType.XMPP_C2S_PING_RESPONSE_EVENT);
			ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
		} else {
			ALLog.d("服务器发送s2c心跳包");
		}
	}

	/******************************* voip *************************************/

	@Override
	public void onGetMakeVoipCallResult(int code, String session) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_MAKE_CALL_RESULT);
		data.setResponseCode(code);
		ALMessage msg = new ALMessage();
		msg.setVoipSession(session);
		msg.setType(ALMessage.MAKE_CALL);
		// msg.setFromNick("alonso");
		data.setMessage(msg);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetAcceptVoipCallResult(int code, String sessionId,
			ALMessage msg) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_ACCEPT_INCOMMING_CALL_RESULT);
		data.setResponseCode(code);
		if (msg != null) {
			msg.setType(ALMessage.ACCEPT_CALL);
			// Message msg = new Message();
			msg.setVoipSession(sessionId);
			// msg.setVoipIp(ip);
			// msg.setVoipPort(port);
			data.setMessage(msg);
		}
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetRejectVoipCallResult(String sessionId) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_REJECT_INCOMMING_CALL_RESULT);
		data.setResponseCode(0);
		ALMessage msg = new ALMessage();
		msg.setVoipSession(sessionId);
		msg.setType(ALMessage.REJECT_CALL);
		data.setMessage(msg);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetHandUpVoipCallResult(String sessionId) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_HANDUP_CALL_RESULT);
		data.setResponseCode(0);
		ALMessage msg = new ALMessage();
		msg.setVoipSession(sessionId);
		msg.setType(ALMessage.HANDUP_CALL);
		data.setMessage(msg);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetEnterBaoMiHuaResult(int)
	 */
	@Override
	public void onGetEnterBaoMiHuaResult(int code) {
		// TODO Auto-generated method stub

		// 进入爆米花
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_ENTER_BAO_MI_HUA_RESULT);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetExitBaoMiHuaResult(int)
	 */
	@Override
	public void onGetExitBaoMiHuaResult(int code) {
		// TODO Auto-generated method stub
		// 退出爆米花
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_EXIT_BAO_MI_HUA_RESULT);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onGetXiehouResult
	 * (int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetXiehouResult(int code, boolean hasMore, DatingUser user) {
		// TODO Auto-generated method stub
		// 进入邂逅
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_ENTER_XIEHOU_RESULT);
		data.setResponseCode(code);
		data.setBoolean(hasMore);
		data.setData(user);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetVoipRecordResult(int, int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetVoipRecordResult(int code, int type, boolean hasMore,
			ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHECK_VOIP_RECORD_RESULT);
		data.setResponseCode(code);
		data.setBoolean(hasMore);
		data.setData(users);
		data.setIntData(type);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onSetVoipCallPriceResult(int)
	 */
	@Override
	public void onSetVoipCallPriceResult(int code) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_SET_VOIP_CALL_PRICE_RESULST);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetVoipCallPriceListResult(int, java.util.ArrayList)
	 */
	@Override
	public void onGetVoipCallPriceListResult(int code,
			ArrayList<CallPrice> prices) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHECK_VOIP_CALL_PRICE_LIST_RESULT);
		data.setResponseCode(code);
		data.setData(prices);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetVoipCallHistoryDetailResult(int code, String jid,
			ArrayList<CallDetail> calls, boolean hasMore) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_CHECK_CALL_HISTORY_DETAIL_RESULT);
		data.setResponseCode(code);
		data.setJid(jid);

		data.setBoolean(hasMore);
		data.setData(calls);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetDeleteVoipCallHistoryDetailResult(int code, String jid) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_DELETE_CALL_HISTORY_DETAIL_RESULT);
		data.setResponseCode(code);
		data.setJid(jid);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/******************************* 功能处理 *************************************/
	private void handleNewMessage(ALMessage msg) {
		// ALLog.d("收到来自 " + msg.getFromNick() + " 的消息 " + msg.getBody());
		// Message m = new Message(msg.getTo(), msg.getFrom());
		// m.setType(Message.TEXT_MSG);
		// m.setBody(msg.getBody());
		// m.getMsgId();
		// // 把收到的消息发回去
		// ALLocalEnv.adapter.xmppSendMessage(m);
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_MESSAGE_PACKAGE_RECEIVE_EVENT);
		data.setMessage(msg);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/******************************* 用户相关 *************************************/

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetDiscoveryUsersResult(int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetDiscoveryUsersResult(int code, boolean hasMore,
			ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_DISCOVERY_RESULT);
		data.setResponseCode(code);
		data.setData(users);
		data.setBoolean(hasMore);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetSearchUsersResult(int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetSearchUsersResult(String type, int code, boolean hasMore,
			ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEvent data = new ALXmppEvent(
				ALXmppEventType.XMPP_GLOBAL_SEARCH_RESULT);
		data.setResponseCode(code);
		data.setData(users);
		data.setBoolean(hasMore);
		data.setStrData1(type);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetRankUsersResult(int, int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetRankUsersResult(int type, int code, boolean hasMore,
			ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_RANK_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setData(users);
		data.setIntData(type);
		data.setBoolean(hasMore);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetRankingRankResult(int, java.lang.String, java.lang.String,
	 * java.lang.String)
	 */
	@Override
	public void onGetRankingRankResult(int code, String popular, String rich,
			String glamour, String popularValue, String richValue,
			String glamourValue) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_RANKING_RANK_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		HashMap<String, String> ranks = new HashMap<String, String>();
		ranks.put("popular", popular);
		ranks.put("rich", rich);
		ranks.put("glamour", glamour);
		ranks.put("popularValue", popularValue);
		ranks.put("richValue", richValue);
		ranks.put("glamourValue", glamourValue);
		data.setData(ranks);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetFriendsAndFansResult(int, int, boolean, java.util.ArrayList, int,
	 * java.lang.String)
	 */
	@Override
	public void onGetFriendsAndFansResult(int type, int code, boolean hasMore,
			ArrayList<User> users, int count, String version,
			final String specialFavoritesCount) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_FRIENDS_LIST_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setData(users);
		data.setBoolean(hasMore);
		data.setIntData(type);
		// 版本号
		data.setStrData1(version);
		// 当前数目
		data.setStrData2(count + "");
		// 相互关注
		data.setStrData3(specialFavoritesCount);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	@Override
	public void onGetFavoritesEachOtherResult(int code, boolean hasMore,
			ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_CHECK_FAVORITES_EACH_OTHER_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setData(users);
		data.setBoolean(hasMore);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetDeletFriendOrFansResult(int, int, java.lang.String)
	 */
	@Override
	public void onGetDeletFriendOrFansResult(int type, int count,
			String version, String jid, final int code) {
		// TODO Auto-generated method stub

		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_DELET_FRIENDS_OR_FANS_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		User u = new User(jid);
		data.setData(u);
		data.setIntData(type);
		// 版本号
		data.setStrData1(version);
		// 当前数目
		data.setStrData2(count + "");
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetAddNormalOrSpecialFavoritesResult(int, int, java.lang.String,
	 * com.alstudio.pojo.module.user.User)
	 */
	@Override
	public void onGetAddNormalOrSpecialFavoritesResult(int type, int code,
			String version, User user) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_ADD_USER_NORMAL_OR_SPECIAL_FAVORITES_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setData(user);
		data.setIntData(type);
		// 版本号
		data.setStrData1(version);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onSetUserNoteNameResult(int, java.lang.String)
	 */
	@Override
	public void onSetUserNoteNameResult(int code, String jid) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_SET_USER_NOTENAME_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setStrData1(jid);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetUserProfileResult(int, com.alstudio.pojo.module.user.User)
	 */
	@Override
	public void onGetUserProfileResult(int code, User u) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_PROFILE_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setData(u);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetModifyUserProfileResult(int)
	 */
	@Override
	public void onGetModifyUserProfileResult(int code) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_MODIFY_USER_PROFILE_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*********************************** 經濟系統 **********************************************/

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetClearMoneyOrPointHistoryResult(int, int)
	 */
	@Override
	public void onGetClearMoneyOrPointHistoryResult(int code, int type) {
		// TODO Auto-generated method stub
		// 删除积分或者账单记录
		ALXmppEventType eventType = ALXmppEventType.XMPP_DELETE_USER_MONEY_OR_POINTS_HISTORY_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setIntData(type);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetUserPointsResult(int, java.lang.String)
	 */
	@Override
	public void onGetUserPointsResult(int code, String points) {
		// TODO Auto-generated method stub
		// 獲取積分
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_POINTS_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setStrData1(points);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetEconomicRecordsResult(int, int, boolean, java.util.ArrayList)
	 */
	@Override
	public void onGetEconomicRecordsResult(int code, int type, boolean hasMore,
			ArrayList<EconomicRecords> economicRecords) {
		// TODO Auto-generated method stub
		// 获取积分或者账单记录
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_MONEY_OR_POINTS_HISTORY_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setBoolean(hasMore);
		data.setData(economicRecords);
		data.setIntData(type);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetRechagePriceResult(int, java.lang.String, java.util.ArrayList)
	 */
	@Override
	public void onGetRechagePriceResult(int code, String gold,
			ArrayList<RechargeItem> rechargeItems) {
		// TODO Auto-generated method stub

		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_RECHARGE_PRICE_RESULT;
		ALXmppEvent data = new ALXmppEvent(eventType);
		data.setResponseCode(code);
		data.setStrData1(gold);
		data.setData(rechargeItems);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(data);

	}

	/****************************************************************************/
	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onVAuthetication
	 * (int, com.alstudio.module.xmpp.protocol.xmpp.data.VauthData)
	 */
	@Override
	public void onVAuthetication(int code, VauthData data) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_START_VAUTH_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(data);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onVAutheticationState(int,
	 * com.alstudio.module.xmpp.protocol.xmpp.data.VauthData)
	 */
	@Override
	public void onVAutheticationState(int code, VauthData data) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_VAUTH_STATE_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(data);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onCommitVoiceIntroEvent(int)
	 */
	@Override
	public void onCommitVoiceIntroEvent(int code) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_SET_VOICE_INTRO_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onGetUserOptEvent
	 * (int, com.alstudio.utils.notification.SystemSettings)
	 */
	@Override
	public void onGetUserOptEvent(int code, SystemSettings settings) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_OPTION_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(settings);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	@Override
	public void onGetBindEmailResultEvent(int code) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_BIND_EMAIL_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}
	
	/* (non-Javadoc)
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onGetBindEmailSuccessEvent(int)
	 */
	@Override
	public void onGetBindEmailSuccessEvent(int code) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_BIND_EMAIL_SUCCESS_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}
	
	/* (non-Javadoc)
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onGetBindEmailSendAgainEvent(int)
	 */
	@Override
	public void onGetBindEmailSendAgainEvent(int code) {
		// TODO Auto-generated method stub
		//再发一封 
		ALXmppEventType eventType = ALXmppEventType.XMPP_BIND_EMAIL_AGAIN_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	@Override
	public void onGetBlackListResult(int code, ArrayList<User> users) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_CHECK_BLACK_LIST_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(users);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/************************************** 道具系统 *****************************************************/

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetPropsMallListResult(int, java.util.ArrayList)
	 */
	@Override
	public void onGetPropsMallListResult(int code, ArrayList<Props> propslist) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_PROPS_LIST_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(propslist);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetCurrentBuyPropsInfoResult(int, java.util.ArrayList,
	 * com.alstudio.pojo.module.local.Prop, int)
	 */
	@Override
	public void onGetCurrentBuyPropsInfoResult(int code,
			ArrayList<Prop> propslist, Prop curPorp, int propBuyCount) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_PROPS_PRICE_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		PropsDetail detail = new PropsDetail();
		detail.setCurPorp(curPorp);
		detail.setPropBuyCount(propBuyCount);
		detail.setPropslist(propslist);
		tmp.setResponseCode(code);
		tmp.setData(detail);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#onGetMyPropsResult
	 * (int, java.util.ArrayList, int)
	 */
	@Override
	public void onGetMyPropsResult(int code, ArrayList<Prop> proplist,
			int propSubscribecount) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_PROPS_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(proplist);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetPropsPurchaseInfoListResult(int, java.util.ArrayList)
	 */
	@Override
	public void onGetPropsPurchaseInfoListResult(int code,
			ArrayList<Prop> proplist) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_GET_USER_PROPS_HISTORY_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setData(proplist);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onDeletePropsPurchaseInfoListResult(int, boolean)
	 */
	@Override
	public void onDeletePropsPurchaseInfoListResult(int code, boolean bool) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_DELETE_USER_PROPS_HISTORY_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setBoolean(bool);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.alstudio.module.xmpp.protocol.xmpp.ALXmppEventListener#
	 * onGetEffectivePropResult(int, boolean)
	 */
	@Override
	public void onGetEffectivePropResult(int code, boolean bool) {
		// TODO Auto-generated method stub
		ALXmppEventType eventType = ALXmppEventType.XMPP_ACTIVIE_PROPS_RESULT;
		ALXmppEvent tmp = new ALXmppEvent(eventType);
		tmp.setResponseCode(code);
		tmp.setBoolean(bool);
		ALLocalEnv.mXmppEventNotifyManager.notifyAllListener(tmp);
	}

}
